<?php
namespace app\controllers;
use app\models\PeGoods;
use Yii;
use yii\data\Pagination;
use yii\web\Controller;
/**
 * 
 */

class GoodsController extends Controller
{ 

 public function actionIndex(){
   return $this->render('index');
 }


    public function actionIndex2()
	{ 
	 $data=yii::$app->request->post();
	 // print_r($data);
	 $model=new PeGoods();
	 $model->name=$data['name'];
	 $model->price=$data['price'];
	 $model->stock=$data['stock'];
	 $res=$model->AddIndex();
	    if($res)
	    {
	      return $this->redirect(['goods/show']);
		 }	 

	}  
    public function actionShow()
    {
	    $query = PeGoods::find();
	    $countQuery = clone $query;
	    $pages = new Pagination(['totalCount' => $countQuery->count(),'defaultPageSize' => 5]);
	    $models = $query->offset($pages->offset)
	        ->limit($pages->limit)
	        ->all();

	    return $this->render('show', [
	         'models' => $models,
	         'pages' => $pages,
	    ]);

    }
   public function actionDel(){
   	 $id=$_GET['id'];
   	 // print_r($id);
   	 $model=new PeGoods();
   	 $del=$model->del($id);
   	 if($del)
   	 {
      return $this->redirect(['goods/show']);
   	 }else{
   	 	echo "É¾³ýÊ§°Ü";
   	 }
   }

}

?>